﻿using System.Configuration;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace Eneta.Portal.Common
{
    /// <summary>
    /// Wrapper class for IoC/DI container. Currently works with Unity.
    /// </summary>
    public static class Resolver
    {
        /// <summary>
        /// Resolves the instance with given type and returns resolved instance.
        /// </summary>
        /// <typeparam name="T">The type of instance to resolve.</typeparam>
        public static T Resolve<T>() where T : class
        {
            var container = new UnityContainer();
            var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Containers.Default.Configure(container);

            return container.Resolve<T>();
        }
    }
}
